﻿namespace Game {

	class Screen {

		field _w; // width
		field _h; // height
		field _0; // native screen object

		field _b; // blits

		constructor(window, width, height) {
			argmatch(ANYTHING, INT, INT) {
				this._0 = window;
				this._w = width;
				this._h = height;
				this._b = [];
			} else {
				throw new InvalidArgumentException();
			}
		}
		
		property width { get { return this._w; } }
		property height { get { return this._h; } }

		method fill(r, g, b) {
			argmatch(INT, INT, INT) {
				this._b.clear();
				this.drawRectangle([r, g, b], 0, 0, this._w, this._h);
			} else {
				throw new InvalidArgumentException();
			}
		}

		method blit(img, x, y) {
			@fast_list_add(this._b, 1, img._0, x, y);
		}

		method drawCircle(color, x, y, r, border=null) {
			argmatch(LIST, INT, INT, INT, NULL) {
				@fast_list_add(this._b, 6, color, x, y, r);
			} else argmatch(LIST, INT, INT, INT, INT) {
				@fast_list_add(this._b, 7, border, color, x, y, r);
			} else {
				throw new InvalidArgumentException();
			}
		}

		method drawEllipse(color, x, y, width, height, border=null) {
			argmatch(LIST, INT, INT, INT, INT, NULL) {
				@fast_list_add(this._b, 4, color, x, y, width, height);
			} else argmatch(LIST, INT, INT, INT, INT, INT) {
				@fast_list_add(b, 5, border, color, x, y, width, height);
			} else {
				throw new InvalidArgumentException();
			}
		}

		method drawRectangle(color, x, y, width, height, border=null) {
			argmatch(LIST, INT, INT, INT, INT, NULL) {
				@fast_list_add(this._b, 2, color, x, y, width, height);
			} else argmatch (LIST, INT, INT, INT, INT, INT) {
				@fast_list_add(this._b, 3, border, color, x, y, width, height);
			} else {
				throw new InvalidArgumentException();
			}
		}

		method drawPolygon(color, points) {
			argmatch(LIST, LIST) {
				@fast_list_add(this._b, 8, color, points);
			} else {
				throw new InvalidArgumentException();
			}
		}

		method drawText(color, text, x, y) {
			argmatch(LIST, STRING, INT, INT) {
				@fast_list_add(this._b, 9, color, text, x, y);
			} else {
				throw new InvalidArgumentException();
			}
		}
	}
}